<?

class CTRLnews extends CONTROL {

	function __construct( $vars ) {
		global $Object;
		
		$this->_addvars( $vars );

		if( $this->action != "list" )
			$Object = $this->create_object();
		
	}

#	Object list.
	function filter_list() {
		global $Request;
		
		return "
		ref.seed([
			new Element( 'h1' ).update( '" . ucfirst( $this->vars->descr ) . "' ),
			lst = new List({ type: ref.vars.type, descr:'" . (( $this->vars->boxdescr )? $this->vars->boxdescr : $this->vars->descr ) . "', blank:'add {$this->vars->type}'})
		]);
		
		lst.seed( ". $Request->parse_list( "ID, ID as key_0, <%lang:nameid%> as key_1, date( date ) as key_2" ) ." );";
		
	}


#	Edit Object.
	function filter_edit() {
		global $Engine, $DB, $Object;
		
		$type = $this->vars->type;
		
		if( $twitter = $DB->query_direct("SELECT * FROM `types` WHERE `key` = 'social.twitter'" )) {
			
			$Twitter = new TWITTER();
			$post = $Twitter->reference_post( $Object->type, $Object->id );
			$tweetline = "new Shift({ type:'social.twitter', descr:'Tweet', value:" . (( $Object->values['meta']->tweetid )? 1 : 0 ) . ", requestfunc:'publish', objid:{$Object->id}, field:'active', objtype:'{$Object->type}' }),";
		}

		return "
			ref.seed([
				
				new Element( 'h1' ).update( \"Beheer $type '". (( $Object->get( "nameid" ) )? $Engine->text->get( $Object->get( "nameid" ) ) : $Object->id ) . "'\" ),
				new Textfield({ descr:'name $type', type:'$type', parentid:{$Object->id}, textid:". $Object->get( "nameid" ) .", values:". json_encode( $Engine->text->filter( $Object->get( "nameid" ) )) ." }),
				new Htmlfield({ descr:'text $type', type:'$type', parentid:{$Object->id}, textid:". $Object->get( "contid" ) .", values:". json_encode( $Engine->text->filter($Object->get( "contid" ), 'long' )) ." }),
				new Options({ descr:'Opties', floats: [
					new Shift({ type:'$type', descr:'Published', value:" . $Object->get( 'active' ) . ", field:'active', objid:{$Object->id} }),
					$tweetline
					new Ajxfield({ type:'$type', descr:'datum', objid:{$Object->id}, field:'date', value:'{$Object->get('date')}', extend:'cal' })
				]})
			]);";
	}


}



